package edu.upenn.yas;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class User extends ActionSupport {

    private String username;
    public String getUsername() { return username; }

    private String firstName;
    public String getFirstName() { return firstName; }
    
    private String lastName;
    public String getLastName() { return lastName; }

    private String location;
    public String getLocation() { return location; }

    private String profession;
    public String getProfession() { return profession; }

    private String age;
    public String getAge() { return age; }

    private List<UIDTitlePair> userPosts = null;

    public String execute() {
        Map session = ActionContext.getContext().getSession();
        if (session.get("login") != null) {
            String username = (String)session.get("username");
            List<String> userInfo =
                QueryEngine.instance.GetUserInfo(username);
            username = userInfo.get(0);
            firstName = userInfo.get(1);
            lastName = userInfo.get(2);
            location = userInfo.get(3);
            profession = userInfo.get(4);
            age = userInfo.get(5);
            userPosts = QueryEngine.instance.getUserPosts(username);
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public List<UIDTitlePair> getUserPosts() { return userPosts ; }
    public void setUserPosts(List<UIDTitlePair> userPosts) {
        this.userPosts = userPosts;
    }

    public static class UIDTitlePair {
        private String uid;
        public String getUid() { return uid; }
        private String title;
        public String getTitle() { return title; }
        public UIDTitlePair(String uid, String title) {
            this.uid = uid;
            this.title = title;
        }
    }

}

